﻿ 
var EasyUICreateModel = $.extend(TradeModel, {
    selRow: null, 
    editor:{
	    title: "属性",
		winid:'EasyUICreate_EditForm',
		formid:'EasyUICreate_EditForm_fm',
		width:720,
		height:300
	},  
    postAction: 'add',
    url: '/sysmgr/easyuicreate', 
    title: "快速创建",
    idField: "TABLE_NAME",
    titleField: "TABLE_COMMENT",
    toolbar: 'EasyUICreate_Toolbar',
    datagrid: 'EasyUICreate_Grid' 
}); 
 
EasyUICreateModel.reload =function() {
	//fun_ReloadEasyUICreateList();
	  $('#EasyUICreate_EditForm').dialog('close'); 
} 


function fun_FindRowById(id) {
    var cRows = $('#EasyUICreate_Grid').datagrid('getRows');
    if (id == undefined || id == '' || id == null) return null;
    for (i = 0; i < cRows.length; i++) {
        if (cRows[i][EasyUICreateModel.idField] == id) {
            return cRows[i];
        }
    }
    return null;
}




function fun_ShowEasyUICreateEditForm(rowData) {  
    EasyUICreateModel.selRow = rowData; 
        EasyUICreateModel.postAction = 'update'; 
        
    $('#EasyUICreate_EditForm_fm').form('clear' );
    EasyUICreateModel.selRow['PACKAGE']='sysmgr';
    $('#EasyUICreate_EditForm_fm').form('load', EasyUICreateModel.selRow); 
}



function viewCreate() {
	var url=Onluy.basePath()+'/sysmgr/easyuicreate/'+$('#htmlmodel').combobox( 'getValue');
	var data =$("#EasyUICreate_EditForm_fm").serializeObject();  
	url+='?TABLE_NAME='+data['TABLE_NAME']+'&PACKAGE='+data['PACKAGE'];
	 $('#viewiframe').attr('src',url);
}

function fun_SaveEasyUICreate() {
	EasyUICreateModel.submit();
	
}
function fun_DelEasyUICreate( id,title) {
	EasyUICreateModel.del(id,title);
} 

function fun_EasyUICreateSearchbox(value, name) {
    if (value == "" || value == null) {
        $.messager.alert('提示', '请输入关键字!', 'info');
    }
    else {
        $('#EasyUICreate_Grid').datagrid('reload');
    }

}
 
function fun_ReloadEasyUICreateList() {
    $('#EasyUICreate_Grid').datagrid('reload');
}
 


$(function () {   
    $('#EasyUICreate_Grid').datagrid({
        pageSize: 20,
        fit: true,
        singleSelect: true,
        checkbox: false,
        rownumbers: false,
        fitColumns: true,
        pagination: true, //分页控件 
        method: 'post',
        idField: EasyUICreateModel.idField,
        treeField: EasyUICreateModel.titleField,
        url: Onluy.basePath()+EasyUICreateModel.url+'/list',
        loader:EasyUICreateModel.Loader,
        toolbar: '#EasyUICreate_Toolbar', 
        columns: [
            [ 
           { title: '表名', field: 'TABLE_NAME', width: 120, sortable: true } 
            ] 
        ], 
        onLoadError: function (res) {
        	EasyUICreateModel.ShowException(res); 
        },
        onLoadSuccess: function (data) {
        	if(data.success){
        		
        	}
        	else{
        		 $.messager.alert('提示', data.msg );
        	} 
        },
        onSelect: function (rowIndex, rowData) {
            fun_ShowEasyUICreateEditForm(rowData);
        },
        onBeforeLoad: function (param) { 
            param['catchKey'] = Math.random();
            param['name'] = $('#EasyUICreate_ss').searchbox('getName');
            param['value'] = $('#EasyUICreate_ss').searchbox('getValue');
        }
    });
    //设置分页控件  
    var p = $('#EasyUICreate_Grid').datagrid('getPager');
    $(p).pagination({ 
        pageList: [10,20, 30, 50, 100], //可以设置每页记录条数的列表  
        beforePageText: '', //页数文本框前显示的汉字  
        afterPageText: '/ {pages}',
        displayMsg: '总数{total}',
        onBeforeRefresh: function () {
            $(this).pagination('loading');
            $(this).pagination('loaded');
        }
    });

});

